from pydantic import BaseModel, Field
from datetime import datetime, date
from typing import Optional

class TeacherBase(BaseModel):
    user_id: int = Field(..., description="用户ID")
    teacher_no: str = Field(..., description="工号", max_length=20)
    teacher_name: str = Field(..., description="教师姓名", max_length=50)
    gender: int = Field(..., description="性别：1-男 2-女")
    birth_date: Optional[date] = Field(None, description="出生日期")
    id_card: Optional[str] = Field(None, description="身份证号", max_length=20)
    phone: Optional[str] = Field(None, description="联系电话", max_length=20)
    email: Optional[str] = Field(None, description="邮箱", max_length=100)
    subject_code: Optional[str] = Field(None, description="任教科目编码", max_length=20)
    job_title: Optional[str] = Field(None, description="职称", max_length=50)
    status: int = Field(1, description="状态：0-离职 1-在职")

class TeacherCreate(TeacherBase):
    """创建教师时使用的模型"""
    pass

class TeacherUpdate(BaseModel):
    """更新教师时使用的模型"""
    user_id: Optional[int] = None
    teacher_no: Optional[str] = None
    teacher_name: Optional[str] = None
    gender: Optional[int] = None
    birth_date: Optional[date] = None
    id_card: Optional[str] = None
    phone: Optional[str] = None
    email: Optional[str] = None
    subject_code: Optional[str] = None
    job_title: Optional[str] = None
    status: Optional[int] = None

class Teacher(TeacherBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True